Ext.define("jwawa.erp.framework.IframePanel", {
    extend: 'Ext.panel.Panel',
    margins: '0 0 0 0',
    autoScroll: false,
    border: false,
    closable: true,
    frameLoaded: false,
    initComponent:  function() {
        var me = this;
        if (me.iframe_url != null || me.iframe_url != ''){
            me.html = '<iframe style="overflow:auto;width:100%;height:100%;" frameborder="0"  src="' + me.iframe_url + '"></iframe>';
            me.addListener('afterrender', function(){
                me.setLoading(true);
                var ifmDom = me.el.query('iframe')[0];
                var ifm = Ext.get(ifmDom);

//                document.onclick = function(){alert(111);}

                ifm.addListener('load', function(){
                    me.frameLoaded = true;
                    ifmDom.contentWindow['ownerCt'] = me;
//                    ifmDom.contentWindow.document.onclick=function(){
//                        if (document.fireEvent) {
//                            (document.fireEvent('onclick'));
//                        } else {
//                            var evObj = document.createEvent('Events');
//                            evObj.initEvent('click', true, false);
//                            document.dispatchEvent(evObj);
//                        }
//                    };
                    Ext.defer(function(){me.setLoading(false)}, 100);
                });
            });


            // fix the iframe load bug
            me.addListener('activate', function(obj){
                var ifmDom = me.el.query('iframe')[0];
                var shellRendered = ifmDom.contentWindow['shell'] == null ? false : true;

                if(!shellRendered && me.frameLoaded){
                    me.setLoading(false);
                    me.setLoading(true);
                    ifmDom.contentDocument.location.reload(true);
                }
            });
        }
        me.callParent(arguments);
    }
});